bug fixes from Peter's note