some code cleanup and gofmt