simplify and eliminate TOCTOU.
remove stray endif
one more search path.