fix the last chunk bug