Error handling

This pull request is a continous strive to improve error handling in the project.