fixed bug with passing $i as a parameter to an external function call