Added application close handling code