Optimized the EventListener onMessage() method