added better history handling