Add fail flag, some bug fixed