Fixed exit bug

Fixed a bug where the program does not end even when it encounters
an error.

Now the application (properly) exits upon errors.