Remove unused code that causes an exception in rare cases and add a unit...

... test for that case. Fixes #1748. It looks like the name and code are fetched at the start element method above, which catches `currentState`, `previousState`, and `instanceState`. In those cases this removed code was never called, but in a rare error case with an incorrect string passed for state it was triggered and that in turn triggered exceptions.