Edited Question 5 solution