properly ignore invalid files, escape html, refactoring