improved validation and generation somewhat