refractoring the code