Skipping sub directories

@voidlock some minor refactoring and and skipping an entry if it's a directory.