Refactored the some code