Fixed memory allocation problem