move pointers out of while loop