Refactored code for more reuse.