Incorporating Michael's patch and avoiding many 'unused variable' warnings