Working code. First attempt.