Removed JS error on pages without sort button (es5 and non-standard); cleaned code