First cut, tested locally, seems to work OK.