Optimize the history command