Update of KML functions

Multiple changes to KML functions, including legend creation.