code and plots first pass