revised and simplified code for drawFigure method