take out alphabetical sorting & do a little optimization