merged code from mavi into trip function