completed kernel folding optimization