added exit function on last page