First pass at supporting OSX plus a bit of clean up.