Moved some stuff around to be more readable