fix chunk function