Fixed mouse trail calculation, which now also can handle loops