added functionality for dynamic memory