Refactor to use dict instead of list when passing lines to writer