test for error first; then default to working code