This 500 was just for an example. The first code should return your current setting and then you should set maxSize accordingly. 

Anyway, is it possible to attach code of this UDF?