material sorting and error on delete if in use