Moved some code out of the main loop in send_files() into a new