memory allocation fixes