added logic for the exercise