Completed code and plots