Moved some stuff to cpp