cleanup and sort master