Adding null check around remove method