improve exception handling when removing files