Fixes for upload

Many fixes, see commits.