Reorganize upload function and indents fix