Added some code to handle socket commands