solved problem 2. solution could be more concise