optimized algorithm and measurement completed