midterm code first attempt