adding safety check before removing nil