fix last chunk bug