Remove redundant code
Big refactor.

Push some independent code to support.js file.

Start adding control structure for using service and stream sockets.