Refactorise the code.