Added check for NULL pointer