OS X (initial) port

Please review the addition of const to passing Value type by reference.
The other changes should be self explanatory via the commit messages.