Refactor: remove phase code duplication.