Better media sorting and debug logging