split large cpp file
added tests + minor bug fixes