Improved beacon discovery code.