cleanup and sorting