Cleanup ProcessEventsWithTriggerOffset

Fix PEP8 violations!
Breaks some parts into functions
Again checked: same results as old method
Add tests for new methods

Fix some broken tests
Make some functions class/static methods.
Makes them easier to test.