Refactoring as specified by various TODOs.