[#87][#129] move log deletion to beginning of function