db active record, coding style, bug fixes