improvements suggested by David Saff