correctly check for existence of directory