90%-broken event-handling code and some bugfixes + trace printfs to help me diagnose stuff