add unique function and improve sanitize function

Titles returned by sanitize will never be empty.
Unique function ensures unique filenames.