Bigfix and code refactoring to eliminate some globals and use $modx->config.