Bug fixes and improvements

@sunglim See comments in the code comparison.
The code before wouldn't handle other commonly used extensions for HTMLs.