KML export: Many corrections.

Improved the somewhat awkward code. Added tests.