added function and minimize allocation