Tidied up upload function