Improved error handling and some code formatting.
Merge pull request #1 from anubiann00b/master

Improved error handling and some code formatting.