Finishing transition to event handling approach.
Refactoring of complexity and minor code style fixes.