refactored midterm 1