Unify key encoding function (from hydra-spec)

Also minor cosmetic changes and update to management client and event
namespaces