Incremental cleanup

This PR just moved code around. There are no changes to behavior.