improved error handling, introduced a debug command line option