ENH: Refactored code