fix for overrunning array bounds