consolidate enable_modules loops into a function for simplicity and DRY - benchmarks show no significant difference in performance