Refactored socket code to be more modular and readable, should help accelerate progress on backend dev