implementing the loop, update and draw function