refactored and added comments to excercise 4