Refactoring diagnosis backend.