Added Close() method and used it in tests.