added option to specify action on close