Refactored csv import code