Refactor the activerecord tasks