More refactoring/bugfixes in CMake files