Format code using gofmt

Also, change some reflect hackerty into a type switch.