Change setHistory function a bit and works well now