Moved history logic to handler.