Tests added to CMakeLists and refactored