fixes #5787 Cant add events

Fixed the issue and pushed the code for review, please check it.