adding infrastructure, splitting functionality into lib module