cleanup all the code, scan mode works smoothly, but just too slow --#