moved sorting before redraw and drawing objects