Fixed a bug with MacOSX (#12). Closes #3 #5 #9 #12