Refactor to idiomatic go