clean up code, and add rescan button