Fixed bugs checking for non-trivial loops