Refactored for reuse.