Refactor html insertion