Generalized the code