Fixed OSX code signing and some code cleanup.

The major change in this pull request is adding support for code signing on OS X.