Hi,
I am not sure if it would be possible to implement it much better.
If you use convolutions as MM, then it will be just saving a bit of memory by wrapping the above code in a Function.
If you want to use other algorithms, I am not even sure it is possible to do it.