Refactored Code for Darwin and Linux