Replace buffer closing hack with a proper plugin