Factored next available file into its own function