RecordIterator and re-organize functions in library.cc