Adding a null check to support empty collections