cid#705051 Dereference after null check

Change-Id: I6b7adb593efa137bb09b3b8d49539f6cd405dd20
cid#705053 Dereference after null check

re-arrange the code to help coverity out

Change-Id: Iddc9284cbdcbaae7a0dc17e62d0e8f4b4832297c
cid#735507 Logically dead code

Change-Id: Ie251bca3e4fa7c67aa84c8ff3ae451b0aaa57f44