fixed the free variable(err_msg)