Tiny bug

This is certainly a bug with effect in the peformance. Although it is very small and, eventually, compensated (neither positive nor negative) and thus the final results are the same. I do recognise that this code (mainly in the algorithm part) is a bit messy; but I guess that this contributes pretty well towards the point I am intending to transmit here: making things nice is OK; but, firstly, make sure that the basic ideas/principles are clear.