Added more code and I am trying to generalize the code