some refactoring and solutions for challenges 4 and 5