Add ability to hook outgoing commands and cancel them

Other misc fixes too.