improve DOMElements constructor and remove redundant whitespaces