refactored csv loops