work correctly for optimized algo.