Refactored to compile on mac