Improve database logic for past years