some corrections to dynamic memory allocation