Rearranged source to make a little more sense