added dynamic memory allocation functionality