Pull event handling into a factory in UI

- Some style fixes
- Updated TODO