Fix substitution when switchValue changes more than once

The switchElements wasn't being updated correctly when switchValue changed more than once between draws.