minor refactoring on error conditions