Improved backend history code and added automatic history rotation based on the frontend 'expire' setting