Bug with memory allocation fixed