Micro-optimizations on the algorithms