Fixed problems with Legend

Control if there are one or more LAYERS. Created function to manage white spaces into layer names