Refactor history fns to limit scope of effectful code