Refactored socketEvents and tests