fix err variable in if scope