Removed common hsmgw, replaced with locals, and cut out unused code.