fix bug and improve stability