Refactored out phase 3 to faciliate testing