First attempt at problem 3