refactor to lib modules