Updated CMakeLists.txt and added a couple of bugfixes.