zsh: more sophisticated cleanup function