Changed defineEvent to when