refactor of go code