Rearranged some logic.