Adapted code for building on OS X 10.7 - 10.9

The changes work both on 10.7 and 10.9 and probably 10.8. They also remove some namespace ambiguity that might cause problems on other systems in the future.