Improve event system and fix bugs