Removing unused functions, cleaning up syntax and style, adding hpgw, gi, gx and agi.