Improve $Loop option

0: stop, 1: loop, 2: rewind