Media renaming: simplify calculation of new filenames and general code tidy