Refactored code out into separate module.