Rearranged some of the code.