Add some tests, and service refactor