Refactored beacon monitoring code