Fix Uncaught TypeError: Cannot read property 'length' of undefined

Fix Uncaught TypeError: Cannot read property 'length' of undefined