Fix small bug leading to last chunk of entities not being written