Moved folder checking into its own function