fixed bug calling drawing function many times