rearranging some lines of code