Repaired main functionality