fixed boundary issue in kernel function