added some safety checks in synthesis
added id caching