More accurate check of file descriptors

the "if fd" condition doesn't work for stdin(0), which is perhaps must be redirected to /dev/null as well.
Let's be more verbose and make a check for None