Improved error handling

I believe the changes are best practices Golang-wise. Let me know your thoughts.