refactor of scan funcitonality