Some refactoring of active record