Fixes bug in upload among other things