Some refactoring of log/csv functionality