Refactored for better reuse.