bug fix in handling error