Make error factory function and minor style fixes