reordered history.py to further condense code