Moved ActiveRecord code to separate file