More generic tests and fixed leaks in tests