working on exit function