Making the code more general