implement error avoiding, and fix several