clean up file heads and tails