Refactor so there are no more global variables
Requires go1.1 - 1.03 doesn't support method values,
and I was too lazy to write wrappers