Fix type errors and 'shadowed variable' warnings.