Added a clean closing code