Added before close handler