refractoring and small fix