Refactored the code ex10