implementtation and refactoring of phase 4 finished