Added dynamic memory allocation