final codes and plots