First attempt at problem 1