Add file/directory check
Fix loop start