Fixes for DOM handling and added tests.