code cleaning; progressed with generalization