add dynamic memory management