fix buffer exhaust problem
encapsulate reading byte