added nullpointer check