First phase of second refactor working