refractoring and cleanup