Fix some bugs, logout move to sockets, new js functions