Added error 500, better memory management while file upload/download