added kernel size check to avoid problems with big kernels