added sorting to draw and renamed functions