Add basic error checking
Make error factory function and minor style fixes
Merge pull request #21 from eush77/error-checking

Add basic error checking