a little faster by re-organizing loops

But it is still slower than BCR-on-rope. I am going to try another way of
implementation. Not necessarily faster, but will use less memmory.