Refactored out phase one for testing purposes