Fix for Uncaught exception: TypeError: Cannot call method 'indexOf' of undefined