Bug fix

- wrong variable and function scopes
- change event names overall