Replaced recursive addSignal call with a while loop.