midterm, refactored to OOP