Beginning of an exit function (still bugged)