fixed composition issue with sapply with more than 2 levels