Rewrote scanNext. Infinite loop fixed