Various improvements suggested by Duncan