trying to do the same thing using a class but now not working