Miscellaneous refactoring.
Add some headers for OSX.