Moved some statements around so the program makes more sense.