moved a lot of logic to DomElement and removed duplication in client.js