Add some history management

sets an upper limit to history