Added code from Peter Norvig's 'Design of Computer Programs'