improve html file generating logic