Reworked to use a scan pointer.