Refactored to incorporate teacher feedback.