Refactor libs and add 2 more tests.