Improve history handling