move code to lib