Added option to prevent automatic closing