Fixed bug in history function