Refactor all lib and test.