Remove code duplication, extract shared patterns, and eliminate type casts and `any` types. Run after implementing new features.
Remove code duplication, extract shared patterns, and eliminate type casts and `any` types. Run after implementing new features.