various fixes
preserve error codes properly in delete_files function