Add file extension to output and use hash for sanitized file names
Add more argument validation with slight refactoring