Refactor output reading