Proper cleanup on close