Rewritten for efficiency.
Rewritten for efficiency.