fixed a bug that was caused when I replaced for loops with apply_dispatch (accidently screwed up the for loop logic, thus an incorrect distance field was generated).