Refactoring and cleanup.

Removed some duplicate code around the event handlers and normalized some names and this/self references.