move CMDs plot to its own function