Add server and fix some bugs