Added some null checks.