gofmt + better error handling

gofmt's the code. Also cleaned up error handling for Write call.
Removed some print statements, etc.