refactored handling realtime events