added getNextValue function for displayImage