Fixed drawLegend call order

Fixed an error where drawLegend was being called out of order