Modify code to use active record
Merge branch 'ar'