Moved some code for easier overwiev