Refactor beaconize code