refactored draw code