better drawing code for functions