Refactor corrected logic in convolution.cpp