modifies query and db cap for performance