moving code into lib