Restructured to eliminate redundant code