Moved some functions around so they ordered more neat and tidy.