Added a slighly optimized algorithm with pseudo-prediction