some fixes in memory allocation