modify to use dynamic memory create