TMDM-7702: code refine and a bug fix