fix buffer size and reorganize mine loop