new version with flat-template