Modularize upload function