There are two equal ifs, one inside another. If the first one is true, then the second one is true.
As the code was before, toHTML added empty elements to mapValue to check for their existance. Now first it check for their existance and then for their non-emptiness.
This is the second try... The first time git ate my homework :-)