Fix integer overflow

Fixes CID #966079, #966078
Remove unused pointers

Fixes #966530, #966532