Check null before using a dom

Check null before using a dom