Fixed "Cannot read property 'type' of undefined"