Fix incorrect order of event execution