Changed how sort works and fixed table header bug