refractoring code on setting the limit