Improvements suggested by jkh