Generalized the code, though the implementation has not really changed