Fix some bugs with how autocomplete works with command history. Multiple words would be picked from history and not always with the prefix removed.