Move some code around (preparing for next commit). No semantic changes.