refactored the rendering logic to graphics.py