Fixed obvious bug that broke everything; added more thorough filename sanitization.