It is not clear why certain Value::err_uint values get returned throughout clarity and at what points they get returned. Perhaps map these magic numbers (1 or 2) to a variable so its clear. Add some comments. See if there is needless mapping to errors happening before converting immediately to these Value::err_uints.