Modified code by exercise