Refactoring: improve performance of selecting IDs and loops visability