fixed bug in error-handling