Added some NULL protection.