Refactored original source, get CMake to work later