Fixed the function so that it accounts for the number of treatment arms