Added memory allocation handling.