Changed raising KeyError -> ValueError (Python3 compat)