Fix failing specs, some more refactoring
Reduce some complexity in ActiveRecord queries