kmlExport: refactoring and adding tests.

This is work in progress.