only works for square kernels