Refactored by Michael B.