Organized the code a little bit to make it more readable.