bug fix & swapped Q & R and q & r in d res mhe if