Fix some gapless repeat related bugs. Fixes #426.