Fix Repository.register to replace an old one correctly

in case a new one is inserted before the old one.
Merge pull request #238 from YungSang/topic

Fix Repository.register to replace an old one correctly, in case a new one is inserted before the old one.