Remove case statement as it is redundant in the else
Extracting un-dry sql to scope for reuse
Merge pull request #482 from ready4god2513/chores/dryup-code

Chores/dryup code