added all changes to implement activerecord