Improved drawing function