Moved more code around, getting a bit more neat