Refactoring and reindentation
Added hack for Macintosh compatibility