Make ActiveRecord worked
Refactor code