fixed 'indexOf of undefined' error