Refactored the Code.