Rearranged code a bit.