added null pointer checks