Some changes to reduce many duplicate queries