Added proper cleanup to the tests. Fixes #449