fixed #357 and did a lot of event refactoring