minor rearranging of code