refactor draw function