Refractored the code.