ported to OSX. not tested; almost definitely needs more work.