Added some null checks