Moved this line up, and generalized the code.