agent threading and event system fixes, minor style fixes