Add NULL protection to all functions.