implement repeat, fix some bugs