rearranging code and add local scanner