solved chal 6 in need of refactoring