Performance and refactoring

Performance via better use of enum logic for history