Added util functions from Phabricator.
Converted global array access to use idx function.