Fix very unlikely NULL deref
Fix uneccesary double assign
Remove dead test code