fix bug and change the leaving mode