Cleanup go code and make it slightly more idiomatic.