improve write-html function