add null checks to fix crashes