Solution from office hours 5