added error checking for -p and -n option code paths