refactor local variable im to imag