finished writing code for plan synthesis + duplication