refactored upload and added option to create error file