Added some additional null checks.