Minor bug fixes/improvements

These changes address all the issues in #1 (thanks to @Fink-sixis) as well as the following:

- CMake based build system to address linker ordering issues
- Fixed mac/linux problems. The code now compiles without any change on Mac and Linux