move code into lib/