Remove package variables for tracking handlers

Previously various handlers were stored in maps with IDs, but because there was
no synchronization, it meant that some functions were not safe for concurrent
use.

Rather than add synchronization, I've removed the maps and used pointers
instead of IDs. This is concurrency-safe and cheaper since no
map lookups are required.