Relooper improvements

Added C++11's for-range loops, as well as some refactoring / cleanups.