Chores/dryup code

@cantino I would love to contribute a bit to the project.  Just wanted to get a bit acquainted with the code base and do a bit of super minor clean up.

This just removes the extraneous when clause as well as extracts a duplicated sql statement out and in to a scope.