cleaned up matrix convolution function