Moved some code around. No functional change.