Fixed a crash bug, fixed timing issues with events