Refactored code for reuse.