major update and conversion to library