used Jon's caTegory flattening code