Remove unnecessary code and generalize