Move code into a helper function.

Move code that always runs after doUndefinedAtom into doUndefinedAtom
for readability.