Moved file dialogue code into its own function.