refactored upload script