refacter the code