code refactored in order to be runnable on MAC