added better error-checking to file uploads