improved upload function and added other conditions