major fixes plus sorting