better error code handling