Fixed chunk writing issue