WIP, moving code into lib