code refractoring and testing