Added error checking for memory allocation