Finished basic event handler. Done.

System, disregarding tests and optimizations, is done and ready for
testing. Will add comments to make the code more readable, and will add
assert statements and other debugging help to make the system easier to
test.