refactor code and  server interface