Refactoring, and fix a couple of SafeHaskell-related things