Replace all db queries with ActiveRecord calls