Misc fixes including fixing the history sort