Refactor the code 2