Moved more code to cpp files