Refactor and test metadata/filename string handling