Replace deprecated APIs with new ones

This PR mainly replaces all APIs which have been deprecated due to Mac OS X 10.6 with new ones.

Please review my changes at your leisure. Thanks !