simplified redirection handling

thanks to @cdent for the pointer