Refrector the code