Fixed potential memory leaks. Each array allocated with new [n] must be deallocated using delete [].