add exception handing to on close