moving navigation generation out of while loop