Moved some code to cpp file.