refactored history handling