Refactored SQL