Fixed a number of issues preventing compilation on MacOSX Mountain Lion.