Formatting, error handling.
Merged my stuff in.
Merge pull request #1 from anubiann00b/master

Formatting and minor optimizations.