Fixed exit function