Some other optimizations. The current version was, during my trials, at least 3 times as fast as the original