Refactored out db queries