Refactored the code 1