private List <RaceLap> GetLapsByLapNumber(int lapNumber, bool searchDownForPreviousLapsForEveryDriver) { List <RaceLap> ret = new List <RaceLap>(); ret = Laps.Get(lapNumber); if (searchDownForPreviousLapsForEveryDriver) { List <Driver> drivers = Laps.GetDrivers().ToList(); foreach (var lap in ret) { if (drivers.Contains(lap.Driver)) { drivers.Remove(lap.Driver); } } int lastDriversCount = drivers.Count; while (drivers.Count > 0) { Driver driver = drivers[0]; for (int i = lapNumber - 1; i > 0; i--) { RaceLap lap = Laps.Get(i, driver); if (lap != null) { ret.Add(lap); drivers.Remove(driver); break; } } if (lastDriversCount == drivers.Count) { throw new Exception("Cannot get last previous lap of driver " + driver.NameSurname + ". Invalid data."); } else { lastDriversCount = drivers.Count; } } } return(ret); }