Moved to library; added tests.