Improvement: step0 possible efficiency improvement
Is there any reason why you cycle 3 times over all columns?
Is that not possible to do all that at ones?
I guess that is not a great improvement in terms of performances, but it may clarify what you do.