More refactoring

Optimised upload logic.