Got rid of globals
Moved filename getting function to inside where it's used
Moved HTML page generation to one function.
Refactoring
Fixed html escaping of path names