merging Omid's codes