AppMsg comm draft. Phase algo adjustment

Adjusted algorithm for phase detection using medians.