Fix a bug in switching buffer