Fix -range for -stdin and tidy up