moved the hack outside the switch statement and improved checking event order conditions