Pseudo-code attempt.