Merge pull request #1147 from AltGr/code-cleanup

Fixed warnings and exception catching.