refractoring some code