Refactored code to allow it to compile on MacOS