Fixed some bugs in file upload and attachments