Added legend plotting
minor code cleaning