Fixing code and build issues for mac os.