Added check for registered events is undefined