Shortened the code

Moved more functions within the sub methods.