changed code to use socket io