Implemented enhancement #52, plus minor changes.