Implement proper close