refactor the service and add more tests