Pass by reference in loop issue fixed.