Fixing small mistakes and deduplicating code