added duplication_limit option and fixed some bugs