Fixed "Cannot read property 'length' of undefined"