Move methods to library.py; add remaining tests.