refactor go code