modifications to support case-insensitivity, throwing on invalid inputs to Decode()