refactored drawing functions