Improvement of the code

Found 3 Possible null pointer dereference with cppcheck
It is doing redundant check and creation of variable that can be unused in some case