Refactor to have lib support