Homework. First attempt.