js event timing bugfix