Merged (some of) Miguels changes.

Signed-off-by: Gordon Smith <gordon.smith@lexisnexis.com>