added some NULL checks