Moved some code for neatness.