minor rewrite and fixes