Adding check before cleaning the buffer