Fixed bug in error handling. Thanks to Anton Lindqvist (anton at basename.se) for spotting.