Moved main upload method to the top.

This makes it easier to understand the code.