fix buffer undderflows