extract code to lib