refactor executable to use Active Record queries