Improve scan time. Still a bit of mess. WIP