MAC-OS porting

Fixed issues to make it work on MAC-OS.