MANTA-17 fix for annoying endless loop, possibly caused by compiler bug. Fixed by rearranging the loop :-)