updated so that time difference is included and phase is no longer wrapped around minimal difference.