aded check if any lines are in buffer before clearing it, prevents useless work and seg fault when no lines were allocated yet