refactoring of phase 2