Code simplification and cleanup