refactor code into beginning of draw loop