Better session handling and history loading