add CMakeLists.txt and refactored a bit