WIP: Refactor some code so that it can be called by more than just one method. No functionality change.