ENH: Refactored the code.