Fixed a few bugs. Will build on OSX.