Moved the parts of the code where they belong