working for any number of classes