Further refactor redirection io logic to remove duplication