Add missing include statements. Add nullcheck.