Database queries refactored.