fix gcc cannot call member function without object error
define variable outside of loop scope