Fixing performance issue in for comprehension