improved version of addToHistory : for scrolling