added a bit to find the minimum distance to an available flag and go to that flag
still working out some kinks so it's commented out