code cleanup and better history display