Refactoring and added libraries for Mac/Linux