Fixing removeChild issue using conditional checks. Might need to be revisited.