Code refactoring for first exercise