Relooper improvements

Added C++11's for-range loops, as well as some refactoring / cleanups.

I did a quick benchmark of `ensure_relooper`, and its performance seems to be unaffected by the changes.