Added if statement to check for null value before dynamic event assignment