Patch from Felipe Kellermann, fix endless loop when first > last and