added a on close function