Refactor things into lib/.
Fix dates problem in tests.