Added a middleware for the services, added and refactored some tests.