Fix multiple bugs

- Fix duplication
- Fix event undefined in firefox
indentation has changed here, are you sure?