Bugfix regarding closing services; added unit test for bugfix