fix html issues
fix coding style
wrap long if statement
put opening of files in with clause