Added debugging and a null check.