Works on OSX + a bit of cleanup