fixed getLatest for new database layout