Refactored code. Reenabled support for csv files.