exception handling and some code refactoring
Merge pull request #5 from massyl/master

exception handling and some code refactoring