Refactors a bit, adds some commands, and failing tests.

Nested elements have to be supported.