partialy reworked the logic behind uploading the files