Implementation of Close() that does not crash