Refactoring to get file sending to work