Rearranged the code to be more readable.