Fixed many socket related issues. Certain edge cases caught for now
Merged client-side code into gh-pages branch