Refactor to use next with named pipe