improved finding lowest id