Rearranged solution a bit.