Moved code to cpp file