Improved error handling

Script should terminate immediately after fatal errors to avoid
unexpected side effects.
Merge pull request #9 from arax/exit_fix

Improved error handling