optimize getNames() by pre-sorting the names