Does a shitload of refactoring to remove the endless loop.