added code to handle destroying legends and removing them through removeMap and destroy functions