Moved update and draw code into functions and resolved naming errors