Let's move this to it's own file. It looks good and we might want to use it in TypedPipe.