Refactored and commented sockEvents.js