Generalized some code