Added assert to prevent forever loops.