Fixed potential infinite loop in removeRecursive method

Change-Id: If8905120b5babaa586e79d6f583b347824988fd0