I haven't really found a good way to not call it twice, unfortunately. Pulling it out as its own thing, called once, has no effect since we want to do these checks (error matching and properly-set attributes) as we set the attribute to a different value each time.