Moved code to cpp