Handle dynamic history length.
Limit history to 30 elements.