lib-ify code