Added NullPointerException check