Added functions for training and Testing Phase1 and Phase2