Implemented phase calculation