finished refacotring generalization code