Improved error message logging,fixed code issues
Merge pull request #14 from gnuman/code-refactor-pull-request

Improved error message logging,fixed code issues