Modified loop condition to include last value high.