Added Legend and functionality