Refactor code

Remove some duplicated OS X code.