refractoring code in collections