Handle exit in a better way