Finding the optimal number of components