Refactor directory check and add check to initial traversal