add HTML support, some refactoring