bug-fix for off-by-one (causing free to seg fault)