Refactored db querys