Moved some things around to make functions much easier to read.