@mgcL 
Could you please update your codes according to the new solution?