Handle close at exit