fix possible buffer overruns