Added additional checks to fix NPE regressions

Change-Id: Ic1c54c000b22b27a776827a9e3ac8b0ff2a78c26
Signed-off-by: John May <john.wilkinsonmay@gmail.com>