improved error haldling